<template>
  <div class="category">
    <h1>当前求和为：{{ sum }}</h1>
    <h2>当前求和十倍为：{{ bigSum }}</h2>
    <h3 style="color: red">下方组件总人数是{{ personList.length }}</h3>
    <h3>我在{{ school }}学习{{ subject }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select>
    <button @click="increment(n)">+</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementOdd(n)">当前求和为奇数再加</button>
    <button @click="incrementWait(n)">等一等再加</button>
  </div>
</template>

<script>
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";
export default {
  name: "CountVue",
  data() {
    return {
      // 用户选择的数据
      n: 1,
    };
  },
  computed: {
    ...mapState(["sum", "school", "subject", "personList"]),

    // ****************************************************************

    ...mapGetters(["bigSum"]),
  },
  methods: {
    // 借助mapMutations生成对应方法，方法会调用commit联系mutations
    ...mapMutations({ increment: "JIA", decrement: "JIAN" }),
    // ...mapMutations(["JIA", "JIAN"]),

    // ********************************************************************

    // 借助mapActions生成对应方法，方法会调用dispatch联系actions
    ...mapActions({ incrementOdd: "jiaOdd", incrementWait: "jiaWait" }),
    // ...mapActions(["jiaOdd", "jiaWait"]),
  },
};
</script>

<style scoped>
button {
  margin-left: 10px;
}
</style>